package org.admanager.piadlpattern.plugin.diagram.part;

import org.admanager.piadladmanagement.plugin.piadladmanagement.CBAPattern;
import org.admanager.piadladmanagement.plugin.piadladmanagement.PiadladmanagementPackage;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.CBAPatternEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponent2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentComponentCompartment2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentComponentCompartmentEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentName2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentNameEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentPort2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PComponentPortEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnector2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorConnectorCompartment2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorConnectorCompartmentEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorName2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorNameEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorRole2EditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConnectorRoleEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConstraintEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PConstraintNameEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PMultiplicityEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PRoleEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PRoleNameEditPart;
import org.admanager.piadlpattern.plugin.diagram.edit.parts.PRoleRoleCompartmentEditPart;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;

/**
 * This registry is used to determine which type of visual object should be
 * created for the corresponding Diagram, Node, ChildNode or Link represented
 * by a domain model object.
 * 
 * @generated
 */
public class PiADLADManagementMetamodelVisualIDRegistry {

	/**
	 * @generated
	 */
	private static final String DEBUG_KEY = "org.admanager.piadlpattern.plugin.diagram/debug/visualID"; //$NON-NLS-1$

	/**
	 * @generated
	 */
	public static int getVisualID(View view) {
		if (view instanceof Diagram) {
			if (CBAPatternEditPart.MODEL_ID.equals(view.getType())) {
				return CBAPatternEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		return org.admanager.piadlpattern.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
				.getVisualID(view.getType());
	}

	/**
	 * @generated
	 */
	public static String getModelID(View view) {
		View diagram = view.getDiagram();
		while (view != diagram) {
			EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
			if (annotation != null) {
				return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$
			}
			view = (View) view.eContainer();
		}
		return diagram != null ? diagram.getType() : null;
	}

	/**
	 * @generated
	 */
	public static int getVisualID(String type) {
		try {
			return Integer.parseInt(type);
		} catch (NumberFormatException e) {
			if (Boolean.TRUE.toString().equalsIgnoreCase(
					Platform.getDebugOption(DEBUG_KEY))) {
				PiADLADManagementMetamodelDiagramEditorPlugin.getInstance()
						.logError(
								"Unable to parse view type as a visualID number: "
										+ type);
			}
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static String getType(int visualID) {
		return Integer.toString(visualID);
	}

	/**
	 * @generated
	 */
	public static int getDiagramVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (PiadladmanagementPackage.eINSTANCE.getCBAPattern().isSuperTypeOf(
				domainElement.eClass())
				&& isDiagram((CBAPattern) domainElement)) {
			return CBAPatternEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static int getNodeVisualID(View containerView, EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		String containerModelID = org.admanager.piadlpattern.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
				.getModelID(containerView);
		if (!CBAPatternEditPart.MODEL_ID.equals(containerModelID)) {
			return -1;
		}
		int containerVisualID;
		if (CBAPatternEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = org.admanager.piadlpattern.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = CBAPatternEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		switch (containerVisualID) {
		case CBAPatternEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponentEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponentPort()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponentPortEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnectorRole()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorRoleEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPMultiplicity()
					.isSuperTypeOf(domainElement.eClass())) {
				return PMultiplicityEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPRole().isSuperTypeOf(
					domainElement.eClass())) {
				return PRoleEditPart.VISUAL_ID;
			}
			break;
		case PComponentComponentCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponentPort()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponentPort2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnector2EditPart.VISUAL_ID;
			}
			break;
		case PComponentComponentCompartment2EditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponentPort()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponentPort2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnector2EditPart.VISUAL_ID;
			}
			break;
		case PConnectorConnectorCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPConnectorRole()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorRole2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnector2EditPart.VISUAL_ID;
			}
			break;
		case PConnectorConnectorCompartment2EditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPConnectorRole()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorRole2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnector2EditPart.VISUAL_ID;
			}
			break;
		case PRoleRoleCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPConstraint()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConstraintEditPart.VISUAL_ID;
			}
			break;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static boolean canCreateNode(View containerView, int nodeVisualID) {
		String containerModelID = org.admanager.piadlpattern.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
				.getModelID(containerView);
		if (!CBAPatternEditPart.MODEL_ID.equals(containerModelID)) {
			return false;
		}
		int containerVisualID;
		if (CBAPatternEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = org.admanager.piadlpattern.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = CBAPatternEditPart.VISUAL_ID;
			} else {
				return false;
			}
		}
		switch (containerVisualID) {
		case CBAPatternEditPart.VISUAL_ID:
			if (PComponentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPortEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorRoleEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PMultiplicityEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PRoleEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentEditPart.VISUAL_ID:
			if (PComponentNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentComponentCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConnectorEditPart.VISUAL_ID:
			if (PConnectorNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorConnectorCompartment2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PRoleEditPart.VISUAL_ID:
			if (PRoleNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PRoleRoleCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponent2EditPart.VISUAL_ID:
			if (PComponentName2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentComponentCompartment2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConnector2EditPart.VISUAL_ID:
			if (PConnectorName2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorConnectorCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConstraintEditPart.VISUAL_ID:
			if (PConstraintNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentComponentCompartmentEditPart.VISUAL_ID:
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPort2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnector2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentComponentCompartment2EditPart.VISUAL_ID:
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPort2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnector2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConnectorConnectorCompartmentEditPart.VISUAL_ID:
			if (PConnectorRole2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnector2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConnectorConnectorCompartment2EditPart.VISUAL_ID:
			if (PConnectorRole2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnector2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PRoleRoleCompartmentEditPart.VISUAL_ID:
			if (PConstraintEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static int getLinkWithClassVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		return -1;
	}

	/**
	 * User can change implementation of this method to handle some specific
	 * situations not covered by default logic.
	 * 
	 * @generated
	 */
	private static boolean isDiagram(CBAPattern element) {
		return true;
	}

}
